package com.xlabs.client;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.*;

/**
 * Header class.
 */
public class Header extends Composite {
    /**
     * nickName.
     */
    private String nickName;

    /**
     * Nickname label.
     */
    private Label nickNameLabel;

    /**
     * Initializes an instance of Header.
     */
    public Header() {
        HorizontalPanel panel = new HorizontalPanel();
        panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

        UserAccountServiceAsync userService = UserAccountService.App.getInstance();

        userService.getNickName(new AsyncCallback() {
            public void onFailure(Throwable throwable) {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            public void onSuccess(Object o) {
                 nickName = (String) o;
                 Header.this.setNickName(nickName);
            }
        });

        this.nickNameLabel = new Label(nickName);

        panel.add(nickNameLabel);

        initWidget(panel);
    }

    /**
     * Sets the nickName .
     * @param nickName
     */
    private void setNickName(String nickName) {
        this.nickNameLabel.setText("Hello! " + nickName);
    }

    /**
     * Gets nickName.
     * @return nickName.
     */
    public String getNickName() {
        return nickName;
    }

}
